<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="text">
    <button class="set">存储数据</button>
    <button class="get">获取数据</button>
    <button class="remove">删除数据</button>
    <button class="del">清空所有数据</button>

</body>

<script>
    let text = document.querySelector('input');
    let set = document.querySelector('.set');
    let get = document.querySelector('.get');
    set.addEventListener('click', function() {
        let val = text.value;
        sessionStorage.setItem('uname', val);
    });
    get.addEventListener('click', function() {
        console.log(sessionStorage.getItem('uname'));
    })
</script>

</html>